﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            公司信息管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2011-7-28 16:36:37
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core.Entities.Center;
using BingZi.HY.Core.Message;
using BingZi.HY.Core.Enums;
using BingZi.HY.Core;
using BingZi.HY.Core.WebControls;





namespace BingZi.HY.UI.Center.Manager.app_CompanyUI
{
    public partial class Manager : BingZi.HY.Core.BLL.PageBase
    {
        Int32 IDX = (Int32)BingZi.HY.Core.Common.sink("IDX", BingZi.HY.Core.Enums.MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)BingZi.HY.Core.Common.sink("CMD", BingZi.HY.Core.Enums.MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_Company ut = app_Company.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加公司信息";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看公司信息";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改公司信息";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    
                    if(ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Edit;
            bi.ButtonName = "公司信息";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Delete;
            bi.ButtonName = "公司信息";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_Company ut)
        {
        UserID_Input.Text = UserID_Disp.Text = ut.UserID.ToString();
                UserName_Input.Text = UserName_Disp.Text = ut.UserName.ToString();
                c_Name_Input.Text = c_Name_Disp.Text = ut.c_Name.ToString();
                c_Area_Input.Text = c_Area_Disp.Text = ut.c_Area.ToString();
                c_Type_Input.Text = c_Type_Disp.Text = ut.c_Type.ToString();
                c_Category_Input.Text = c_Category_Disp.Text = ut.c_Category.ToString();
                c_Brand_Input.Text = c_Brand_Disp.Text = ut.c_Brand.ToString();
                c_MainProducts_Input.Text = c_MainProducts_Disp.Text = ut.c_MainProducts.ToString();
                c_BusinessLicence_Input.Text = c_BusinessLicence_Disp.Text = ut.c_BusinessLicence.ToString();
                c_BusinessLicenceSrc_Input.Text = c_BusinessLicenceSrc_Disp.Text = ut.c_BusinessLicenceSrc.ToString();
                c_Address_Input.Text = c_Address_Disp.Text = ut.c_Address.ToString();
                c_Logo_Input.Text = c_Logo_Disp.Text = ut.c_Logo.ToString();
                c_Photo_Input.Text = c_Photo_Disp.Text = ut.c_Photo.ToString();
                c_Introduce_Input.Text = c_Introduce_Disp.Text = ut.c_Introduce.ToString();
                c_HomePage_Input.Text = c_HomePage_Disp.Text = ut.c_HomePage.ToString();
                c_SeoKeyWord_Input.Text = c_SeoKeyWord_Disp.Text = ut.c_SeoKeyWord.ToString();
                c_SeoDescription_Input.Text = c_SeoDescription_Disp.Text = ut.c_SeoDescription.ToString();
                c_LastUserID_Input.Text = c_LastUserID_Disp.Text = ut.c_LastUserID.ToString();
                c_LastTime_Input.Text = c_LastTime_Disp.Text = ut.c_LastTime.ToString();
                c_LastIP_Input.Text = c_LastIP_Disp.Text = ut.c_LastIP.ToString();
                c_State_Input.Text = c_State_Disp.Text = ut.c_State.ToString();
                U_Email_Input.Text = U_Email_Disp.Text = ut.U_Email.ToString();
                U_MSN_Input.Text = U_MSN_Disp.Text = ut.U_MSN.ToString();
                U_QQ_Input.Text = U_QQ_Disp.Text = ut.U_QQ.ToString();
                U_MobilePhone_Input.Text = U_MobilePhone_Disp.Text = ut.U_MobilePhone.ToString();
                U_Phone_Input.Text = U_Phone_Disp.Text = ut.U_Phone.ToString();
                U_Fax_Input.Text = U_Fax_Disp.Text = ut.U_Fax.ToString();
                U_Position_Input.Text = U_Position_Disp.Text = ut.U_Position.ToString();
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        UserID_Input.Visible = false;
        UserName_Input.Visible = false;
        c_Name_Input.Visible = false;
        c_Area_Input.Visible = false;
        c_Type_Input.Visible = false;
        c_Category_Input.Visible = false;
        c_Brand_Input.Visible = false;
        c_MainProducts_Input.Visible = false;
        c_BusinessLicence_Input.Visible = false;
        c_BusinessLicenceSrc_Input.Visible = false;
        c_Address_Input.Visible = false;
        c_Logo_Input.Visible = false;
        c_Photo_Input.Visible = false;
        c_Introduce_Input.Visible = false;
        c_HomePage_Input.Visible = false;
        c_SeoKeyWord_Input.Visible = false;
        c_SeoDescription_Input.Visible = false;
        c_LastUserID_Input.Visible = false;
        c_LastTime_Input.Visible = false;
        c_LastIP_Input.Visible = false;
        c_State_Input.Visible = false;
        U_Email_Input.Visible = false;
        U_MSN_Input.Visible = false;
        U_QQ_Input.Visible = false;
        U_MobilePhone_Input.Visible = false;
        U_Phone_Input.Visible = false;
        U_Fax_Input.Visible = false;
        U_Position_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
        UserID_Disp.Visible = false;
        UserName_Disp.Visible = false;
        c_Name_Disp.Visible = false;
        c_Area_Disp.Visible = false;
        c_Type_Disp.Visible = false;
        c_Category_Disp.Visible = false;
        c_Brand_Disp.Visible = false;
        c_MainProducts_Disp.Visible = false;
        c_BusinessLicence_Disp.Visible = false;
        c_BusinessLicenceSrc_Disp.Visible = false;
        c_Address_Disp.Visible = false;
        c_Logo_Disp.Visible = false;
        c_Photo_Disp.Visible = false;
        c_Introduce_Disp.Visible = false;
        c_HomePage_Disp.Visible = false;
        c_SeoKeyWord_Disp.Visible = false;
        c_SeoDescription_Disp.Visible = false;
        c_LastUserID_Disp.Visible = false;
        c_LastTime_Disp.Visible = false;
        c_LastIP_Disp.Visible = false;
        c_State_Disp.Visible = false;
        U_Email_Disp.Visible = false;
        U_MSN_Disp.Visible = false;
        U_QQ_Disp.Visible = false;
        U_MobilePhone_Disp.Visible = false;
        U_Phone_Disp.Visible = false;
        U_Fax_Disp.Visible = false;
        U_Position_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            int UserID_Value = (int)BingZi.HY.Core.Common.sink(UserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string UserName_Value = (string)BingZi.HY.Core.Common.sink(UserName_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            string c_Name_Value = (string)BingZi.HY.Core.Common.sink(c_Name_Input.UniqueID, MethodType.Post, 100, 1, DataType.Str);
            int c_Area_Value = (int)BingZi.HY.Core.Common.sink(c_Area_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int c_Type_Value = (int)BingZi.HY.Core.Common.sink(c_Type_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            int c_Category_Value = (int)BingZi.HY.Core.Common.sink(c_Category_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            string c_Brand_Value = (string)BingZi.HY.Core.Common.sink(c_Brand_Input.UniqueID, MethodType.Post, 100, 0, DataType.Str);
            string c_MainProducts_Value = (string)BingZi.HY.Core.Common.sink(c_MainProducts_Input.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            string c_BusinessLicence_Value = (string)BingZi.HY.Core.Common.sink(c_BusinessLicence_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            string c_BusinessLicenceSrc_Value = (string)BingZi.HY.Core.Common.sink(c_BusinessLicenceSrc_Input.UniqueID, MethodType.Post, 150, 0, DataType.Str);
            string c_Address_Value = (string)BingZi.HY.Core.Common.sink(c_Address_Input.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            string c_Logo_Value = (string)BingZi.HY.Core.Common.sink(c_Logo_Input.UniqueID, MethodType.Post, 150, 0, DataType.Str);
            string c_Photo_Value = (string)BingZi.HY.Core.Common.sink(c_Photo_Input.UniqueID, MethodType.Post, 150, 0, DataType.Str);
            string c_Introduce_Value = (string)BingZi.HY.Core.Common.sink(c_Introduce_Input.UniqueID, MethodType.Post, 512, 0, DataType.Str);
            string c_HomePage_Value = (string)BingZi.HY.Core.Common.sink(c_HomePage_Input.UniqueID, MethodType.Post, 150, 0, DataType.Str);
            string c_SeoKeyWord_Value = (string)BingZi.HY.Core.Common.sink(c_SeoKeyWord_Input.UniqueID, MethodType.Post, 100, 0, DataType.Str);
            string c_SeoDescription_Value = (string)BingZi.HY.Core.Common.sink(c_SeoDescription_Input.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            int c_LastUserID_Value = (int)BingZi.HY.Core.Common.sink(c_LastUserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            DateTime c_LastTime_Value = (DateTime)BingZi.HY.Core.Common.sink(c_LastTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            string c_LastIP_Value = (string)BingZi.HY.Core.Common.sink(c_LastIP_Input.UniqueID, MethodType.Post, 15, 1, DataType.Str);
            int c_State_Value = (int)BingZi.HY.Core.Common.sink(c_State_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            string U_Email_Value = (string)BingZi.HY.Core.Common.sink(U_Email_Input.UniqueID, MethodType.Post, 50, 1, DataType.Str);
            string U_MSN_Value = (string)BingZi.HY.Core.Common.sink(U_MSN_Input.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            int U_QQ_Value = (int)BingZi.HY.Core.Common.sink(U_QQ_Input.UniqueID, MethodType.Post, 10, 0, DataType.Int);
            string U_MobilePhone_Value = (string)BingZi.HY.Core.Common.sink(U_MobilePhone_Input.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            string U_Phone_Value = (string)BingZi.HY.Core.Common.sink(U_Phone_Input.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            string U_Fax_Value = (string)BingZi.HY.Core.Common.sink(U_Fax_Input.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            string U_Position_Value = (string)BingZi.HY.Core.Common.sink(U_Position_Input.UniqueID, MethodType.Post, 20, 0, DataType.Str);
            app_Company ut = app_Company.FindByKeyForEdit(IDX);
            
            ut.UserID = UserID_Value;
            ut.UserName = UserName_Value;
            ut.c_Name = c_Name_Value;
            ut.c_Area = c_Area_Value;
            ut.c_Type = c_Type_Value;
            ut.c_Category = c_Category_Value;
            ut.c_Brand = c_Brand_Value;
            ut.c_MainProducts = c_MainProducts_Value;
            ut.c_BusinessLicence = c_BusinessLicence_Value;
            ut.c_BusinessLicenceSrc = c_BusinessLicenceSrc_Value;
            ut.c_Address = c_Address_Value;
            ut.c_Logo = c_Logo_Value;
            ut.c_Photo = c_Photo_Value;
            ut.c_Introduce = c_Introduce_Value;
            ut.c_HomePage = c_HomePage_Value;
            ut.c_SeoKeyWord = c_SeoKeyWord_Value;
            ut.c_SeoDescription = c_SeoDescription_Value;
            ut.c_LastUserID = c_LastUserID_Value;
            ut.c_LastTime = c_LastTime_Value;
            ut.c_LastIP = c_LastIP_Value;
            ut.c_State = c_State_Value;
            ut.U_Email = U_Email_Value;
            ut.U_MSN = U_MSN_Value;
            ut.U_QQ = U_QQ_Value;
            ut.U_MobilePhone = U_MobilePhone_Value;
            ut.U_Phone = U_Phone_Value;
            ut.U_Fax = U_Fax_Value;
            ut.U_Position = U_Position_Value;
            
            Int32 rInt =0; if (CMD == "New")
            {
                rInt = ut.Insert();
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加公司信息成功!(ID:{0})", rInt);
                if(CMD == "Edit")
                    OpTxt = string.Format("修改公司信息成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
